﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Video.Application.Contract.Base;
using Video.Application.Contract.UserInfos;
using Video.Application.Contract.UserInfos.Dtos;

namespace Video.HttpApi.Host.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class UserInfoController : ControllerBase
    {
        private readonly IUserInfoService _userInfoService;
        public UserInfoController(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }
        [HttpGet] 
        public async Task<UserInfoRoleDto> GetAsync()
        {
            return await _userInfoService.GetAsync();
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateUserInfo updateUserInfo)
        {
             await _userInfoService.UpdateAsync(updateUserInfo);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="getListInput"></param>
        /// <returns></returns>
        [HttpGet("List")]
        public async Task<PageResultDto<UserInfoDto>> GetListAsync([FromQuery]GetListInput getListInput)
        {
            return await _userInfoService.GetListAsync(getListInput);
        }
        [Authorize(Roles = "admin")]
        [HttpDelete]
        public async Task DeleteAsync(IEnumerable<Guid> guid)
        {
             await _userInfoService.DeleteAsync(guid);
        }
        [Authorize(Roles ="admin")]
        [HttpPut("enable")]
        public async Task EnableAsync(IEnumerable<Guid> guid, bool enable = true)
        {
            await _userInfoService.EnableAsync(guid, enable);
        }
    }
}
